package com.lch.mp.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.lch.mp.pojo.Emp;
import com.lch.mp.service.IEmpService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import java.time.LocalDate;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author author
 * @since 2025-03-25
 */
@CrossOrigin
@RestController
@RequestMapping("/emp")
public class EmpController {

    @Autowired
    private IEmpService empService;

    @RequestMapping("/list")
    public List<Emp> list() {
        List<Emp> list = empService.list();
        System.out.println(list);
        System.out.println(list.size());
        return list;
    }

    @RequestMapping("/add")
    public Emp add(String ename , Integer sal, LocalDate hiredate) {
        Emp emp = new Emp();
        emp.setEname(ename);
        emp.setSal(sal);
        emp.setHiredate(hiredate);
        emp.setDeptID(1);
        boolean b = empService.saveOrUpdate(emp);
        return emp;
    }

    @RequestMapping("/page")
    public List<Emp> page(Integer pageNum, Integer pageSize) {
        IPage<Emp> page = empService.page(
                new Page<>(pageNum, pageSize),
                new QueryWrapper<Emp>()
                        .like("ename","x")
        );
        return page.getRecords();
    }



}
